--[[========================================================
	LOCALS
========================================================]]--

--	Local input library
sc_input				= {}

--	Local variables used
sc_input.LastUserKeys		= {}

--[[========================================================
	FUNCTIONS
========================================================]]--

--[[----------------------------------------------------]]--
--[[	Initialize custom input stuff for a player		]]--
--[[----------------------------------------------------]]--
sc_input.InitializePlayerInput	= function( ply )

	--	Initialize double-key elements at player's first spawn
	sc_input.LastUserKeys[ ply:EntIndex() ] = { Time = CurTime(), Key = nil }

end

--[[----------------------------------------------------]]--
--[[	Check for double key press						]]--
--[[----------------------------------------------------]]--
sc_input.CheckDoubleKeyPress		= function( ply, key )

	--	Initialize input if not yet done
	if sc_input.LastUserKeys[ ply:EntIndex() ] == nil then
		sc_input.InitializePlayerInput( ply )
	end

	--	Handle double-press
	if tobool( GAMEMODE.Config[ "sc_use_double_press" ] ) then
		if key == sc_input.LastUserKeys[ ply:EntIndex() ].Key then
		
			--	Check that time elapsed between clicks is not too much
			local elapsed	= CurTime() - sc_input.LastUserKeys[ ply:EntIndex() ].Time
			if elapsed < 0.25 then
			
				--	Trigger double key press
				GAMEMODE:DoubleKeyPress( ply, key )
				sc_input.LastUserKeys[ ply:EntIndex() ].Key = nil
				
			else
			
				sc_input.LastUserKeys[ ply:EntIndex() ].Key = key
			
			end
		
		else
		
			sc_input.LastUserKeys[ ply:EntIndex() ].Key = key
		
		end
		
		--	Save time
		sc_input.LastUserKeys[ ply:EntIndex() ].Time = CurTime()
	end

end

--[[========================================================
	GAMEMODE EVENTS
========================================================]]--

--[[----------------------------------------------------]]--
--[[	A key was double-pressed						]]--
--[[----------------------------------------------------]]--
function GM:DoubleKeyPress( ply, key )

	--	Activate fast speed
	if key == IN_FORWARD and ply:KeyDown( IN_SPEED ) then
	
		ply:SetRunSpeed( 250 )
	
	end

end